export default {
  data () {
    return {
      // 回到顶部
      showBackTop: false
    }
  },
  mounted () {
    // 监听顶部距离
    window.addEventListener('scroll', this.scrollToTop)
  },
  methods: {
    // 监听高度
    scrollToTop () {
      const that = this
      let scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
      that.scrollTop = scrollTop
      if (that.scrollTop > 300) {
        that.showBackTop = true
      } else {
        that.showBackTop = false
      }
    },
    // 回到顶部
    backTop () {
      document.body.scrollTop = 0
      document.documentElement.scrollTop = 0
    }
  },
  destroyed () {
    window.removeEventListener('scroll', this.scrollToTop)
  }
}
